package charts;

import interfaces.TagDataGetter;

import java.awt.BorderLayout;
import java.util.Date;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

/**
 * @author Manseer Marcel
 * @author Plavsic Maja
 * @author Pretsch Paul
 */
public class PieChart extends Chart {

	private static final long serialVersionUID = 1L;
	protected final DefaultPieDataset piedata = new DefaultPieDataset();

	public PieChart() {
		super();

		setLayout(new BorderLayout());
		
		JFreeChart chart = ChartFactory.createPieChart("Pie Chart", piedata, true, true, false);

		add(new ChartPanel(chart), BorderLayout.CENTER);
	}
	
	@Override
	public void prepareDataSet(Date since, String... hashtags) {
		super.prepareDataSet(since, hashtags);
		
		this.piedata.clear();

		// request Data for single day
		for (String hashtag : hashtags) {
			this.piedata.setValue(hashtag, 0);
		} 
	}
	
	@Override
	public void setTagData(TagDataGetter twitterData, int oldCount) {
		super.setTagData(twitterData, oldCount);
		
		int oldValue = this.piedata.getValue(twitterData.getTag()).intValue();
		this.piedata.setValue(twitterData.getTag(), oldValue - oldCount + twitterData.getCount());
	}

}
